

#pragma once
#include <stdint.h>
#include <vector>
#include <thread>
#include <assert.h>
#include <atomic>
#include <queue>

namespace FlameEngine
{
	class ThreadJoiner
	{
	public:
		explicit ThreadJoiner(std::vector<std::thread>& threads) :
			m_threads(threads)
		{
		}

		~ThreadJoiner()
		{
			for(unsigned long i = 0; i<m_threads.size(); ++i)
			{
				if(m_threads[i].joinable())
					m_threads[i].join();
			}
		}

	private:
		std::vector<std::thread>& m_threads;
	};




	typedef int Task;
	class ThreadPool
	{
	public:
		ThreadPool(int32_t threadCount=0);
		~ThreadPool();

		void SubmitTaks(Task task);

	protected:
		//don't change variable order there!!
		std::atomic<bool> m_exist;
		std::queue<int> m_tasks;
		std::vector<std::thread> m_threads;
		ThreadJoiner m_joiner;

		int32_t m_threadCount;

		void Run()
		{
			while(!m_exist)
			{

			}
		}
	};

	
}